package sort.impl;

import sort.BaseSort;

public class Insertion implements BaseSort {
    @Override
    public void safeSort(Comparable[] arr) {
        if(arr == null || arr.length < 2){
            return;
        }
        int len = arr.length;
        for(int i = 1; i < len; i++){
            Comparable get = arr[i];
            int j = i - 1;
            while (j >= 0 && get.compareTo(arr[j]) < 0){
                arr[j + 1] = arr[j];
                j--;
            }
            arr[j + 1] = get;
        }
    }
}
